﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

using LeMigue.Scrum.Iterface.Enum;

namespace LeMigue.Scrum.Iterface.Model
{
    /// <summary>
    /// Representação de um item backlog
    /// </summary>
    public class ItemBacklog : ScrumItem, IHasTask, IHasBacklog, IHasIteration
    {
        /// <summary>
        /// Armazena o Lazy da lista de tarefas
        /// </summary>
        internal Lazy<IList<Task>> _tasks;

        /// <summary>
        /// Armazena o Lazy da lista de subbacklogs
        /// </summary>
        internal Lazy<IList<ItemBacklog>> _backlogs;

        /// <summary>
        /// Armazena o estado do backlog
        /// </summary>
        private ItemBacklogState _state = ItemBacklogState.New;


        public Iteration Iteration { get; set; }

        /// <summary>
        /// Contrutor de um backlog já existente
        /// </summary>
        /// <param name="id">Id do backlog</param>
        /// <param name="title">Titulo do backlog</param>
        public ItemBacklog(int id, string title)
            : base(id, title)
        {
        }

        /// <summary>
        /// Retorna a lista das Tarefas
        /// </summary>
        public IList<Task> Tasks
        {
            get { return new ReadOnlyCollection<Task>(_tasks.Value); }
        }

        /// <summary>
        /// Retorna a lista dos SubBacklogs
        /// </summary>
        public IList<ItemBacklog> Backlogs
        {
            get { return new ReadOnlyCollection<ItemBacklog>(_backlogs.Value); }
        }

        /// <summary>
        /// Estado do Backlog
        /// </summary>
        public ItemBacklogState State
        {
            get { return _state; }
            set { _state = value; }
        }

        /// <summary>
        /// Seta o Lazy para carregar a lista das Tarefas
        /// </summary>
        /// <param name="tasks"></param>
        public void SetTasks(Lazy<IList<Task>> tasks)
        {
            _tasks = tasks;
        }

        /// <summary>
        /// Seta o Lazy para carregar os SubBacklogs
        /// </summary>
        /// <param name="tasks"></param>
        public void SetBacklogs(Lazy<IList<ItemBacklog>> backlogs)
        {
            _backlogs = backlogs;
        }

        /// <summary>
        /// Retorna se tem ou não tarefas
        /// </summary>
        public bool HasTask
        {
            get { return Tasks.Count > 0; }
        }

        /// <summary>
        /// Retorna se tem ou não ou não sub backlogs
        /// </summary>
        public bool HasBacklog
        {
            get { return Backlogs.Count > 0; }
        }
        
    }
}
